import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 待保养设备信息 */
export interface EquipmnetKeepWait {
  id: number // id
  keepNo?: string // 保养单号
  itemId?: number // 保养项id
  equipmentId?: number // 设备id
  status: number // 保养状态
  planDate: string | Dayjs // 计划保养日期
  remaining?: number // 剩余天数
  dutyUserId?: string // 责任人ID
  dutyUserName: string // 责任人名称
}

// 待保养设备 API
export const EquipmnetKeepWaitApi = {
  // 查询待保养设备分页
  getEquipmnetKeepWaitPage: async (params: any) => {
    return await request.get({ url: `/business/equipmnet-keep-wait/page`, params })
  },

  // 查询待保养设备详情
  getEquipmnetKeepWait: async (id: number) => {
    return await request.get({ url: `/business/equipmnet-keep-wait/get?id=` + id })
  },

  // 新增待保养设备
  createEquipmnetKeepWait: async (data: EquipmnetKeepWait) => {
    return await request.post({ url: `/business/equipmnet-keep-wait/create`, data })
  },

  // 修改待保养设备
  updateEquipmnetKeepWait: async (data: EquipmnetKeepWait) => {
    return await request.put({ url: `/business/equipmnet-keep-wait/update`, data })
  },

  // 更新状态
  updateKeepWaitAndTask: async (data) => {
    return await request.put({ url: `/business/equipmnet-keep-wait/updateStatus`, data })
  },

  // 删除待保养设备
  deleteEquipmnetKeepWait: async (id: number) => {
    return await request.delete({ url: `/business/equipmnet-keep-wait/delete?id=` + id })
  },

  /** 批量删除待保养设备 */
  deleteEquipmnetKeepWaitList: async (ids: number[]) => {
    return await request.delete({
      url: `/business/equipmnet-keep-wait/delete-list?ids=${ids.join(',')}`
    })
  },

  // 导出待保养设备 Excel
  exportEquipmnetKeepWait: async (params) => {
    return await request.download({ url: `/business/equipmnet-keep-wait/export-excel`, params })
  },

  //易损品模块======================================

  // 查询待保养设备分页
  getEquipmnetKeepWaitPageDamage: async (params: any) => {
    return await request.get({ url: `/Damage/equipmnet-keep-wait/page`, params })
  },

  // 查询待保养设备详情
  getEquipmnetKeepWaitDamage: async (id: number) => {
    return await request.get({ url: `/Damage/equipmnet-keep-wait/get?id=` + id })
  },

  // 新增待保养设备
  createEquipmnetKeepWaitDamage: async (data: EquipmnetKeepWait) => {
    return await request.post({ url: `/Damage/equipmnet-keep-wait/create`, data })
  },

  // 修改待保养设备
  updateEquipmnetKeepWaitDamage: async (data: EquipmnetKeepWait) => {
    return await request.put({ url: `/Damage/equipmnet-keep-wait/update`, data })
  },

  // 更新状态
  updateKeepWaitAndTaskDamage: async (data) => {
    return await request.put({ url: `/Damage/equipmnet-keep-wait/updateStatus`, data })
  },

  // 删除待保养设备
  deleteEquipmnetKeepWaitDamage: async (id: number) => {
    return await request.delete({ url: `/Damage/equipmnet-keep-wait/delete?id=` + id })
  },

  /** 批量删除待保养设备 */
  deleteEquipmnetKeepWaitListDamage: async (ids: number[]) => {
    return await request.delete({
      url: `/Damage/equipmnet-keep-wait/delete-list?ids=${ids.join(',')}`
    })
  },

  // 导出待保养设备 Excel
  exportEquipmnetKeepWaitDamage: async (params) => {
    return await request.download({ url: `/Damage/equipmnet-keep-wait/export-excel`, params })
  }
}
